| Conditions | 2 |
| Paths | 128 |
| Total Lines | 111 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 23 | $(document).ready(function () { |
||
| 24 | |||
| 25 | var Settings = function (baseUrl) { |
||
| 26 | this._baseUrl = baseUrl; |
||
| 27 | this._settings = []; |
||
| 28 | }; |
||
| 29 | |||
| 30 | Settings.prototype = { |
||
| 31 | load: function () { |
||
| 32 | var deferred = $.Deferred(); |
||
| 33 | var self = this; |
||
| 34 | $.ajax({ |
||
| 35 | url: this._baseUrl, |
||
| 36 | method: 'GET', |
||
| 37 | async: false |
||
| 38 | }).done(function (settings) { |
||
| 39 | self._settings = settings; |
||
| 40 | }).fail(function () { |
||
| 41 | deferred.reject(); |
||
| 42 | }); |
||
| 43 | return deferred.promise(); |
||
| 44 | }, |
||
| 45 | |||
| 46 | setUserKey: function (key, value) { |
||
| 47 | var request = $.ajax({ |
||
| 48 | url: this._baseUrl + '/' + key + '/' + value, |
||
| 49 | method: 'POST' |
||
| 50 | }); |
||
| 51 | request.done(function () { |
||
| 52 | $('.msg-passwords').removeClass("msg_error"); |
||
| 53 | $('.msg-passwords').text(''); |
||
| 54 | }); |
||
| 55 | request.fail(function () { |
||
| 56 | $('.msg-passwords').addClass("msg_error"); |
||
| 57 | $('.msg-passwords').text(t('passwords', 'Error while saving field') + ' ' + key + '!'); |
||
| 58 | }); |
||
| 59 | }, |
||
| 60 | |||
| 61 | setAdminKey: function (key, value) { |
||
| 62 | var request = $.ajax({ |
||
| 63 | url: this._baseUrl + '/' + key + '/' + value +'/admin1/admin2', |
||
| 64 | method: 'POST' |
||
| 65 | }); |
||
| 66 | request.done(function () { |
||
| 67 | $('.msg-passwords').removeClass("msg_error"); |
||
| 68 | $('.msg-passwords').text(''); |
||
| 69 | }); |
||
| 70 | request.fail(function () { |
||
| 71 | $('.msg-passwords').addClass("msg_error"); |
||
| 72 | $('.msg-passwords').text(t('passwords', 'Error while saving field') + ' ' + key + '!'); |
||
| 73 | }); |
||
| 74 | }, |
||
| 75 | getKey: function (key) { |
||
| 76 | if(this._settings.hasOwnProperty(key)){ |
||
| 77 | return this._settings[key]; |
||
| 78 | } |
||
| 79 | return false; |
||
| 80 | }, |
||
| 81 | getAll: function () { |
||
| 82 | return this._settings; |
||
| 83 | } |
||
| 84 | }; |
||
| 85 | |||
| 86 | |||
| 87 | var settings = new Settings(OC.generateUrl('apps/passman/api/v2/settings')); |
||
| 88 | settings.load(); |
||
| 89 | |||
| 90 | // ADMIN SETTINGS |
||
| 91 | |||
| 92 | // fill the boxes |
||
| 93 | $('#passman_link_sharing_enabled').prop('checked', (settings.getKey('link_sharing_enabled').toString().toLowerCase() === '1')); |
||
| 94 | $('#passman_sharing_enabled').prop('checked', (settings.getKey('user_sharing_enabled').toString().toLowerCase() === '1')); |
||
| 95 | $('#passman_check_version').prop('checked', (settings.getKey('check_version').toString().toLowerCase() === '1')); |
||
| 96 | $('#passman_https_check').prop('checked', (settings.getKey('https_check').toString().toLowerCase() === '1')); |
||
| 97 | $('#passman_disable_contextmenu').prop('checked', (settings.getKey('disable_contextmenu').toString().toLowerCase() === '1')); |
||
| 98 | $('#passman_disable_debugger').prop('checked', (settings.getKey('disable_debugger').toString().toLowerCase() === '1')); |
||
| 99 | $('#vault_key_strength').val(settings.getKey('vault_key_strength')); |
||
| 100 | |||
| 101 | |||
| 102 | $('#passman_check_version').change(function () { |
||
| 103 | settings.setAdminKey('check_version', ($(this).is(":checked")) ? 1 : 0); |
||
| 104 | }); |
||
| 105 | |||
| 106 | $('#passman_https_check').change(function () { |
||
| 107 | settings.setAdminKey('https_check', ($(this).is(":checked")) ? 1 : 0); |
||
| 108 | }); |
||
| 109 | |||
| 110 | $('#passman_disable_contextmenu').change(function () { |
||
| 111 | settings.setAdminKey('disable_contextmenu', ($(this).is(":checked")) ? 1 : 0); |
||
| 112 | }); |
||
| 113 | |||
| 114 | $('#passman_disable_debugger').change(function () { |
||
| 115 | settings.setAdminKey('disable_debugger', ($(this).is(":checked")) ? 1 : 0); |
||
| 116 | }); |
||
| 117 | |||
| 118 | $('#passman_sharing_enabled').change(function () { |
||
| 119 | settings.setAdminKey('user_sharing_enabled', ($(this).is(":checked")) ? 1 : 0); |
||
| 120 | }); |
||
| 121 | |||
| 122 | $('#passman_link_sharing_enabled').change(function () { |
||
| 123 | settings.setAdminKey('link_sharing_enabled', ($(this).is(":checked")) ? 1 : 0); |
||
| 124 | }); |
||
| 125 | $('#vault_key_strength').change(function () { |
||
| 126 | settings.setAdminKey('vault_key_strength', $(this).val()); |
||
| 127 | }); |
||
| 128 | |||
| 129 | if($('form[name="passman_settings"]').length === 2){ |
||
| 130 | $('form[name="passman_settings"]')[1].remove(); |
||
| 131 | } |
||
| 132 | |||
| 133 | }); |
||
| 134 |